package com.szgr.baoyin.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.szgr.baoyin.R;
import com.szgr.baoyin.model.OrderInfo;
import com.szgr.baoyin.model.Refund;
import com.szgr.baoyin.myview.NoScrollListView;
import com.szgr.baoyin.utils.DateUtils;

import java.util.List;

/**
 * Created by yang on 16/1/13.
 */
public class RefundListAdapter extends BaseAdapter {

    private Context mContext;
    private List<Refund> data;
    private View.OnClickListener listener;
    public RefundListAdapter(Context context,List<Refund> data,View.OnClickListener listener){
        mContext = context;
        this.data = data;
        this.listener = listener;
    }
    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if(convertView == null){
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_my_order_list_view,parent,false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        }
        holder = (ViewHolder) convertView.getTag();
        Refund refund = data.get(position);
        holder.nslv_order.setAdapter(new OrderItemNoScrollAdapter1(mContext,refund));

//        int num = 0;
//        for (OrderInfo.MyOrderItem.ExtendOrderGoods eg : extend_order_goods) {
//            num += Integer.parseInt(eg.getGoods_num());
//        }
        holder.tv_orderNum.setText("订单号：" + refund.getOrder_sn());
        holder.tv_num.setText("共" + refund.getGoods_num() + "件商品");
        holder.tv_price.setText("¥" + refund.getRefund_amount() + "元");

//        String state = myOrderItem.getOrder_state();
        holder.tv_btn.setTag(position);
//        switch (state){
//            case "10":
//                holder.tv_btn.setText("去支付");
//                holder.tv_btn.setVisibility(View.VISIBLE);
//                break;
//            case "20":
//                holder.tv_btn.setVisibility(View.GONE);
//                break;
//            case "30":
//                holder.tv_btn.setText("确认收货");
//                holder.tv_btn.setVisibility(View.VISIBLE);
//                break;
//            case "40":
//                holder.tv_btn.setText("去评价");
//                holder.tv_btn.setVisibility(View.VISIBLE);
//                break;
//        }
        holder.tv_btn.setVisibility(View.GONE);
        holder.tv_btn.setOnClickListener(listener);

        String add_time = refund.getAdd_time();
        String s = DateUtils.paseDate1(Long.parseLong(add_time));
        holder.tv_time.setText("下单时间：" + s);

        return convertView;
    }

    public void setData(List<Refund> data) {
        this.data = data;
        notifyDataSetChanged();
    }

    class ViewHolder {
        NoScrollListView nslv_order;
        TextView tv_num;
        TextView tv_price;
        TextView tv_btn;
        TextView tv_orderNum;
        TextView tv_time;

        public ViewHolder(View view){
            nslv_order = (NoScrollListView) view.findViewById(R.id.order_no_scroll_list_view);
            tv_num = (TextView) view.findViewById(R.id.order_goods_num);
            tv_orderNum = (TextView) view.findViewById(R.id.order_number);
            tv_price = (TextView) view.findViewById(R.id.order_goods_price);
            tv_btn = (TextView) view.findViewById(R.id.order_goods_btn);
            tv_time = (TextView) view.findViewById(R.id.add_time);
        }
    }
}
